package com.dbManage.page.record;

import com.dbManage.dao.NoteDao;
import com.dbManage.dao.RecordDao;
import com.dbManage.entity.Note;
import com.dbManage.entity.NoteRecord;
import com.dbManage.entity.User;
import com.dbManage.tools.SessionTool;
import com.wsse.common.tool.TimeTool;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class RecordService {
    @Resource
    RecordDao recordDao;
    @Resource
    NoteDao noteDao;

    public void insertNoteRecord(Note note,String ip){
        NoteRecord noteRecord = new NoteRecord();
        User user= SessionTool.getUser();
        if(user!=null){//登录用户
            noteRecord.setUid(user.getId());
        }else{//未登录
            noteRecord.setUid(0);
        }
        noteRecord.setNid(note.getId());
        noteRecord.setIp(ip);
        noteRecord.setTime(TimeTool.getNow());
        recordDao.insertNoteRecord(noteRecord);
        note.setCount(note.getCount()+1);
        noteDao.updateNoteCount(note);
    }

}
